package com.work.demo.entity;

/**
 * @Param :
 * @Description :
 * @Author : LinYa
 * @Date : 2021/11/4 19:00
 * @return
 * @throws
 */

public class DoubleCheckedLocking {


	private volatile static DoubleCheckedLocking instance;

	private DoubleCheckedLocking() {
	}

	public static DoubleCheckedLocking getInstance() {
		if (instance == null) {                                 // 第一次检查
			synchronized (DoubleCheckedLocking.class) {         // 加锁
				if (instance == null) {                         // 第二次检查
					instance = new DoubleCheckedLocking();                  // instance为volatile，问题得以解决
				}
			}
		}
		return instance;
	}

}